<?php
/**
 * Description: PhpStorm.
 * Author: momo
 * Date: 7/26/24 9:01 AM
 * Copyright: momo
 */


namespace app\admin\controller;


use app\common\enums\ResponseStatusEnum;
use app\common\model\Users;
use think\facade\View;

class AdminAuth
{
    public function login(){
        return View::fetch();
    }

    public function doLogin(){
        $adminUserModel=new Users();
        $where = [
            "user_phone" => $_POST["username"],
            "user_pwd" => md5($_POST["password"])
        ];
        $user=$adminUserModel->oneDetail(Users::class,$where);
        if($user){
            //登录成功
            session("admin_user",$user);
            return json(["status"=>200,"msg"=>"操作成功"]);
        }else{
            //登录失败
            echo json_encode(['status' => 201, 'msg' => "账号或密码错误"]);
            exit();
        }
    }

    /**
     * 退出登录
     */
    public function loginOut()
    {
        session("admin_user", null);
        $this->success("退出成功！", "/admin/login");
    }
}
